﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.InsuranceProducts;

namespace ZBJF.Warranty.BLL
{
    public partial class InsuranceProductsAvailableModelTypeService
    {

        #region 获取保险产品所适用的型号列表 + List<InsuranceProductsAvailableModel> GetAvailableModelTypeList(int cellPhoneServiceProjectID)
        /// <summary>
        /// 获取保险产品所适用的型号列表
        /// </summary>
        /// <param name="cellPhoneServiceProjectID">保险产品服务项目ID</param>
        /// <returns></returns>
        public List<InsuranceProductsAvailableModel> GetInsuranceProductAvailableModel(int cellPhoneServiceProjectID)
        {
           return  (from a in LoadEntities(t => t.CellPhoneServiceProjectID == cellPhoneServiceProjectID)
             join b in ServiceFactory.ProductModelsServiceInstance.LoadEntities(t => true) on a.ModelID equals b.ID into temp1
             from c in temp1.DefaultIfEmpty()
             join d in ServiceFactory.ProductBrandsServiceInstance.LoadEntities(t => true) on c.BrandId equals d.ID into temp2
             from e in temp2.DefaultIfEmpty()
             select new InsuranceProductsAvailableModel()
             {
                 ID = a.ID,
                 ModelID = c.ID,
                 ModelName = c.ModelName,
                 BrandID = e.ID,
                 BrandName = e.BrandName
             }).ToList();

        }
        #endregion

        public IQueryable<InsuranceProductsAvailableModelType> GetInsuranceProductAvailableModel(List<int> cellPhoneServiceProjectIDs)
        {
            return LoadEntities(o => cellPhoneServiceProjectIDs.Contains(o.CellPhoneServiceProjectID));
        }

        #region 删除保险产品所适用的型号列表 
        /// <summary>
        /// 删除保险产品所适用的型号列表
        /// </summary>
        /// <param name="insuranceProductsId">保险产品ID</param>
        /// <returns></returns>
        public bool DeleteInsuranceProductsAvailableModelType(long insuranceProductsId)
        {
            string sql = "DELETE FROM InsuranceProductsAvailableModelType WHERE InsuranceProductsID=@InsuranceProductsID";
            int re= ExcuteSql(sql, new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("InsuranceProductsID", insuranceProductsId) });
            return re > 0;
        }
        #endregion
    }
}
